﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Net;
using System.IO;
namespace ProcessesSMS
{
    /// <summary>
    /// Summary description for CKVN.
    /// </summary>
    public class EDUCATION
    {

        private SMS_MO WMO;
        private SMS_MT WMT;
        //private SMS_LIST WML;
        ArrayList arr = new ArrayList();
        public EDUCATION(SMS_MO MO)
        {
            WMO = MO;
        }

        public EDUCATION()
        {
        }
        public void run()
        {
            WMT = new SMS_MT(WMO);
            string tmpMsg = WMO.Message.Substring(WMO.CommandCode.Length).Trim().Replace("  ", " ").Replace("  ", " ");
            tmpMsg = tmpMsg.Replace("  ", " ").Trim().ToUpper();
            string[] msg = tmpMsg.Split(new char[] { ' ' });           
            //if (strReturnMsg != "")
            //{
                string[] strReturnMsg = GetReturnMsg(msg).Split('|');
                for (int i = 0; i < strReturnMsg.Length; i++)
                {
                    WMT.AddMessage(WMO.UserID, strReturnMsg[i], SMS_ContentType.SMS_TEXT);
                    WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
                }                               
                WMT.Insert();
            //}
            return;
        }
        private string GetReturnMsg(string[] arr)
        {
            string msgBody = string.Empty;
            SMSEDUCATION.SMSReturn smsedu = new ProcessesSMS.SMSEDUCATION.SMSReturn();
            if(arr.Length==2)            
            {
                if (arr[0] == "LD")//xem lich day
                {
                    msgBody = smsedu.XemLichDay(WMO.CommandCode, arr[1]);
                }
                else if (arr[0] == "LH")//xem lich hoc
                {
                    msgBody = smsedu.XemLichHoc(WMO.CommandCode, arr[1]);
                }
                else//xem diem mot mon cua mot sv 
                {
                    msgBody = smsedu.XemDiem(WMO.CommandCode, arr[0], arr[1]);
                }
            }
            else if (arr.Length == 1)
            {
                msgBody = smsedu.XemDiemfull(WMO.CommandCode, arr[0]);
            }
            else
            {
                msgBody = "De xem diem, soan tin theo cu phap: MaTruong MaSV MaMonHoc gui 6572.Vidu: Ban la SV DH Bach Khoa muon xem diem mon Giai Tich,soan: BKA 125842 GiaiTich gui 6572";
            }
            return msgBody;
        }        
    }
}
